<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Numpy的优势 | 机器学习（常用科学计算库的使用）基础定位、目标</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../Numpy/section2.html" />
    
    
    <link rel="prev" href="../Numpy/index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="4.1"
        data-chapter-title="Numpy的优势"
        data-filepath="Numpy/section1.md"
        data-basepath=".."
        data-revision="Sat Jul 20 2019 23:53:14 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        机器学习（常用科学计算库的使用）基础定位、目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="ml_pre/index.html">
            
                
                    <a href="../ml_pre/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        机器学习概述
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="ml_pre/section1.html">
            
                
                    <a href="../ml_pre/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        人工智能概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="ml_pre/section2.html">
            
                
                    <a href="../ml_pre/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        人工智能发展历程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ml_pre/section3.html">
            
                
                    <a href="../ml_pre/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        人工智能主要分支
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ml_pre/section4.html">
            
                
                    <a href="../ml_pre/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        机器学习工作流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ml_pre/section5.html">
            
                
                    <a href="../ml_pre/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        机器学习算法分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="ml_pre/section6.html">
            
                
                    <a href="../ml_pre/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        模型评估
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="ml_pre/section7.html">
            
                
                    <a href="../ml_pre/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        Azure机器学习模型搭建实验
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ml_pre/section8.html">
            
                
                    <a href="../ml_pre/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        深度学习简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="env/index.html">
            
                
                    <a href="../env/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        机器学习基础环境安装与使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="env/section1.html">
            
                
                    <a href="../env/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="env/section2.html">
            
                
                    <a href="../env/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        jupyter notebook使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="Matplotlib/index.html">
            
                
                    <a href="../Matplotlib/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Matplotlib
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="Matplotlib/section1.html">
            
                
                    <a href="../Matplotlib/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Matplotlib之HelloWorld
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="Matplotlib/section2.html">
            
                
                    <a href="../Matplotlib/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        基础绘图功能 — 以折线图为例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="Matplotlib/section3.html">
            
                
                    <a href="../Matplotlib/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        常见图形绘制
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Numpy/index.html">
            
                
                    <a href="../Numpy/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Numpy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="4.1" data-path="Numpy/section1.html">
            
                
                    <a href="../Numpy/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Numpy的优势
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Numpy/section2.html">
            
                
                    <a href="../Numpy/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        N维数组-ndarray
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="Numpy/section3.html">
            
                
                    <a href="../Numpy/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Numpy/section4.html">
            
                
                    <a href="../Numpy/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        ndarray运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Numpy/section5.html">
            
                
                    <a href="../Numpy/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        数组间的运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Numpy/section6.html">
            
                
                    <a href="../Numpy/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        数学：矩阵
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="Pandas/index.html">
            
                
                    <a href="../Pandas/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="Pandas/section1.html">
            
                
                    <a href="../Pandas/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Pandas介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="Pandas/section2.html">
            
                
                    <a href="../Pandas/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Pandas数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="Pandas/section3.html">
            
                
                    <a href="../Pandas/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        基本数据操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="Pandas/section4.html">
            
                
                    <a href="../Pandas/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        DataFrame运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="Pandas/section5.html">
            
                
                    <a href="../Pandas/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Pandas画图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="Pandas/section6.html">
            
                
                    <a href="../Pandas/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件读取与存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="Pandas/section7.html">
            
                
                    <a href="../Pandas/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        高级处理-缺失值处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="Pandas/section8.html">
            
                
                    <a href="../Pandas/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        高级处理-数据离散化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="Pandas/section9.html">
            
                
                    <a href="../Pandas/section9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        高级处理-合并
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="Pandas/section10.html">
            
                
                    <a href="../Pandas/section10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        高级处理-交叉表与透视表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="Pandas/section11.html">
            
                
                    <a href="../Pandas/section11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        高级处理-分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="Pandas/section12.html">
            
                
                    <a href="../Pandas/section12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="ReadingExtension/index.html">
            
                
                    <a href="../ReadingExtension/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        拓展知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="ReadingExtension/1.完整机器学习项目的流程.html">
            
                
                    <a href="../ReadingExtension/1.完整机器学习项目的流程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        完整机器学习项目的流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="ReadingExtension/2.独立同分布.html">
            
                
                    <a href="../ReadingExtension/2.独立同分布.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        独立同分布
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >机器学习（常用科学计算库的使用）基础定位、目标</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="41-numpy&#x4F18;&#x52BF;">4.1 Numpy&#x4F18;&#x52BF;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x76EE;&#x6807;<ul>
<li>&#x4E86;&#x89E3;Numpy&#x8FD0;&#x7B97;&#x901F;&#x5EA6;&#x4E0A;&#x7684;&#x4F18;&#x52BF;</li>
<li>&#x77E5;&#x9053;Numpy&#x7684;&#x6570;&#x7EC4;&#x5185;&#x5B58;&#x5757;&#x98CE;&#x683C;</li>
<li>&#x77E5;&#x9053;Numpy&#x7684;&#x5E76;&#x884C;&#x5316;&#x8FD0;&#x7B97;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="1-numpy&#x4ECB;&#x7ECD;">1 Numpy&#x4ECB;&#x7ECD;</h2>
<p><img src="images/Numpy.png" alt="Numpy"></p>
<p>Numpy&#xFF08;Numerical Python&#xFF09;&#x662F;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x7684;Python&#x79D1;&#x5B66;&#x8BA1;&#x7B97;&#x5E93;&#xFF0C;<strong>&#x7528;&#x4E8E;&#x5FEB;&#x901F;&#x5904;&#x7406;&#x4EFB;&#x610F;&#x7EF4;&#x5EA6;&#x7684;&#x6570;&#x7EC4;</strong>&#x3002;</p>
<p>Numpy<strong>&#x652F;&#x6301;&#x5E38;&#x89C1;&#x7684;&#x6570;&#x7EC4;&#x548C;&#x77E9;&#x9635;&#x64CD;&#x4F5C;</strong>&#x3002;&#x5BF9;&#x4E8E;&#x540C;&#x6837;&#x7684;&#x6570;&#x503C;&#x8BA1;&#x7B97;&#x4EFB;&#x52A1;&#xFF0C;&#x4F7F;&#x7528;Numpy&#x6BD4;&#x76F4;&#x63A5;&#x4F7F;&#x7528;Python&#x8981;&#x7B80;&#x6D01;&#x7684;&#x591A;&#x3002;</p>
<p>Numpy<strong>&#x4F7F;&#x7528;ndarray&#x5BF9;&#x8C61;&#x6765;&#x5904;&#x7406;&#x591A;&#x7EF4;&#x6570;&#x7EC4;</strong>&#xFF0C;&#x8BE5;&#x5BF9;&#x8C61;&#x662F;&#x4E00;&#x4E2A;&#x5FEB;&#x901F;&#x800C;&#x7075;&#x6D3B;&#x7684;&#x5927;&#x6570;&#x636E;&#x5BB9;&#x5668;&#x3002;</p>
<h2 id="2-ndarray&#x4ECB;&#x7ECD;">2 ndarray&#x4ECB;&#x7ECD;</h2>
<pre><code class="lang-python">NumPy provides an N-dimensional array type, the ndarray, 
which describes a collection of &#x201C;items&#x201D; of the same type.
</code></pre>
<p>NumPy&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;<strong>N&#x7EF4;&#x6570;&#x7EC4;&#x7C7B;&#x578B;ndarray</strong>&#xFF0C;&#x5B83;&#x63CF;&#x8FF0;&#x4E86;<strong>&#x76F8;&#x540C;&#x7C7B;&#x578B;</strong>&#x7684;&#x201C;items&#x201D;&#x7684;&#x96C6;&#x5408;&#x3002;</p>
<p><img src="images/&#x5B66;&#x751F;&#x6210;&#x7EE9;&#x6570;&#x636E;.png" alt="&#x5B66;&#x751F;&#x6210;&#x7EE9;&#x6570;&#x636E;"></p>
<p>&#x7528;ndarray&#x8FDB;&#x884C;&#x5B58;&#x50A8;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-comment"># &#x521B;&#x5EFA;ndarray</span>
score = np.array(
[[<span class="hljs-number">80</span>, <span class="hljs-number">89</span>, <span class="hljs-number">86</span>, <span class="hljs-number">67</span>, <span class="hljs-number">79</span>],
[<span class="hljs-number">78</span>, <span class="hljs-number">97</span>, <span class="hljs-number">89</span>, <span class="hljs-number">67</span>, <span class="hljs-number">81</span>],
[<span class="hljs-number">90</span>, <span class="hljs-number">94</span>, <span class="hljs-number">78</span>, <span class="hljs-number">67</span>, <span class="hljs-number">74</span>],
[<span class="hljs-number">91</span>, <span class="hljs-number">91</span>, <span class="hljs-number">90</span>, <span class="hljs-number">67</span>, <span class="hljs-number">69</span>],
[<span class="hljs-number">76</span>, <span class="hljs-number">87</span>, <span class="hljs-number">75</span>, <span class="hljs-number">67</span>, <span class="hljs-number">86</span>],
[<span class="hljs-number">70</span>, <span class="hljs-number">79</span>, <span class="hljs-number">84</span>, <span class="hljs-number">67</span>, <span class="hljs-number">84</span>],
[<span class="hljs-number">94</span>, <span class="hljs-number">92</span>, <span class="hljs-number">93</span>, <span class="hljs-number">67</span>, <span class="hljs-number">64</span>],
[<span class="hljs-number">86</span>, <span class="hljs-number">85</span>, <span class="hljs-number">83</span>, <span class="hljs-number">67</span>, <span class="hljs-number">80</span>]])

score
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([[<span class="hljs-number">80</span>, <span class="hljs-number">89</span>, <span class="hljs-number">86</span>, <span class="hljs-number">67</span>, <span class="hljs-number">79</span>],
       [<span class="hljs-number">78</span>, <span class="hljs-number">97</span>, <span class="hljs-number">89</span>, <span class="hljs-number">67</span>, <span class="hljs-number">81</span>],
       [<span class="hljs-number">90</span>, <span class="hljs-number">94</span>, <span class="hljs-number">78</span>, <span class="hljs-number">67</span>, <span class="hljs-number">74</span>],
       [<span class="hljs-number">91</span>, <span class="hljs-number">91</span>, <span class="hljs-number">90</span>, <span class="hljs-number">67</span>, <span class="hljs-number">69</span>],
       [<span class="hljs-number">76</span>, <span class="hljs-number">87</span>, <span class="hljs-number">75</span>, <span class="hljs-number">67</span>, <span class="hljs-number">86</span>],
       [<span class="hljs-number">70</span>, <span class="hljs-number">79</span>, <span class="hljs-number">84</span>, <span class="hljs-number">67</span>, <span class="hljs-number">84</span>],
       [<span class="hljs-number">94</span>, <span class="hljs-number">92</span>, <span class="hljs-number">93</span>, <span class="hljs-number">67</span>, <span class="hljs-number">64</span>],
       [<span class="hljs-number">86</span>, <span class="hljs-number">85</span>, <span class="hljs-number">83</span>, <span class="hljs-number">67</span>, <span class="hljs-number">80</span>]])
</code></pre>
<p><strong>&#x63D0;&#x95EE;:</strong></p>
<p><strong>&#x4F7F;&#x7528;Python&#x5217;&#x8868;&#x53EF;&#x4EE5;&#x5B58;&#x50A8;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x901A;&#x8FC7;&#x5217;&#x8868;&#x7684;&#x5D4C;&#x5957;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x90A3;&#x4E48;&#x4E3A;&#x4EC0;&#x4E48;&#x8FD8;&#x9700;&#x8981;&#x4F7F;&#x7528;Numpy&#x7684;ndarray&#x5462;&#xFF1F;</strong></p>
<h2 id="3-ndarray&#x4E0E;python&#x539F;&#x751F;list&#x8FD0;&#x7B97;&#x6548;&#x7387;&#x5BF9;&#x6BD4;">3 ndarray&#x4E0E;Python&#x539F;&#x751F;list&#x8FD0;&#x7B97;&#x6548;&#x7387;&#x5BF9;&#x6BD4;</h2>
<p>&#x5728;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x6765;&#x4F53;&#x4F1A;&#x5230;ndarray&#x7684;&#x597D;&#x5904;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> random
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
a = []
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">100000000</span>):
    a.append(random.random())

<span class="hljs-comment"># &#x901A;&#x8FC7;%time&#x9B54;&#x6CD5;&#x65B9;&#x6CD5;, &#x67E5;&#x770B;&#x5F53;&#x524D;&#x884C;&#x7684;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x4E00;&#x6B21;&#x6240;&#x82B1;&#x8D39;&#x7684;&#x65F6;&#x95F4;</span>
%time sum1=sum(a)

b=np.array(a)

%time sum2=np.sum(b)
</code></pre>
<p>&#x5176;&#x4E2D;&#x7B2C;&#x4E00;&#x4E2A;&#x65F6;&#x95F4;&#x663E;&#x793A;&#x7684;&#x662F;&#x4F7F;&#x7528;&#x539F;&#x751F;Python&#x8BA1;&#x7B97;&#x65F6;&#x95F4;,&#x7B2C;&#x4E8C;&#x4E2A;&#x5185;&#x5BB9;&#x662F;&#x4F7F;&#x7528;numpy&#x8BA1;&#x7B97;&#x65F6;&#x95F4;:</p>
<pre><code>CPU times: user 852 ms, sys: 262 ms, total: 1.11 s
Wall time: 1.13 s
CPU times: user 133 ms, sys: 653 &#xB5;s, total: 133 ms
Wall time: 134 ms
</code></pre><p>&#x4ECE;&#x4E2D;&#x6211;&#x4EEC;&#x770B;&#x5230;ndarray&#x7684;&#x8BA1;&#x7B97;&#x901F;&#x5EA6;&#x8981;&#x5FEB;&#x5F88;&#x591A;&#xFF0C;&#x8282;&#x7EA6;&#x4E86;&#x65F6;&#x95F4;&#x3002;</p>
<p><strong>&#x673A;&#x5668;&#x5B66;&#x4E60;&#x7684;&#x6700;&#x5927;&#x7279;&#x70B9;&#x5C31;&#x662F;&#x5927;&#x91CF;&#x7684;&#x6570;&#x636E;&#x8FD0;&#x7B97;</strong>&#xFF0C;&#x90A3;&#x4E48;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E00;&#x4E2A;&#x5FEB;&#x901F;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF0C;&#x90A3;&#x53EF;&#x80FD;&#x73B0;&#x5728;python&#x4E5F;&#x5728;&#x673A;&#x5668;&#x5B66;&#x4E60;&#x9886;&#x57DF;&#x8FBE;&#x4E0D;&#x5230;&#x597D;&#x7684;&#x6548;&#x679C;&#x3002;</p>
<p><img src="images/&#x8BA1;&#x7B97;&#x91CF;&#x5927;.png" alt="&#x8BA1;&#x7B97;&#x91CF;&#x5927;"></p>
<p>Numpy&#x4E13;&#x95E8;&#x9488;&#x5BF9;ndarray&#x7684;&#x64CD;&#x4F5C;&#x548C;&#x8FD0;&#x7B97;&#x8FDB;&#x884C;&#x4E86;&#x8BBE;&#x8BA1;&#xFF0C;&#x6240;&#x4EE5;&#x6570;&#x7EC4;&#x7684;&#x5B58;&#x50A8;&#x6548;&#x7387;&#x548C;&#x8F93;&#x5165;&#x8F93;&#x51FA;&#x6027;&#x80FD;&#x8FDC;&#x4F18;&#x4E8E;Python&#x4E2D;&#x7684;&#x5D4C;&#x5957;&#x5217;&#x8868;&#xFF0C;&#x6570;&#x7EC4;&#x8D8A;&#x5927;&#xFF0C;Numpy&#x7684;&#x4F18;&#x52BF;&#x5C31;&#x8D8A;&#x660E;&#x663E;&#x3002;</p>
<p><strong>&#x601D;&#x8003;&#xFF1A;</strong></p>
<p><strong>ndarray&#x4E3A;&#x4EC0;&#x4E48;&#x53EF;&#x4EE5;&#x8FD9;&#x4E48;&#x5FEB;&#xFF1F;</strong></p>
<h2 id="4-ndarray&#x7684;&#x4F18;&#x52BF;">4 ndarray&#x7684;&#x4F18;&#x52BF;</h2>
<h4 id="41-&#x5185;&#x5B58;&#x5757;&#x98CE;&#x683C;">4.1 &#x5185;&#x5B58;&#x5757;&#x98CE;&#x683C;</h4>
<p>ndarray&#x5230;&#x5E95;&#x8DDF;&#x539F;&#x751F;python&#x5217;&#x8868;&#x6709;&#x4EC0;&#x4E48;&#x4E0D;&#x540C;&#x5462;&#xFF0C;&#x8BF7;&#x770B;&#x4E00;&#x5F20;&#x56FE;&#xFF1A;</p>
<p><img src="images/numpy&#x5185;&#x5B58;&#x5730;&#x5740;.png" alt="numpy&#x5185;&#x5B58;&#x5730;&#x5740;"></p>
<p>&#x4ECE;&#x56FE;&#x4E2D;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x51FA;ndarray&#x5728;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6570;&#x636E;&#x4E0E;&#x6570;&#x636E;&#x7684;&#x5730;&#x5740;&#x90FD;&#x662F;&#x8FDE;&#x7EED;&#x7684;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x7ED9;&#x4F7F;&#x5F97;&#x6279;&#x91CF;&#x64CD;&#x4F5C;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x65F6;&#x901F;&#x5EA6;&#x66F4;&#x5FEB;&#x3002;</p>
<p>&#x8FD9;&#x662F;&#x56E0;&#x4E3A;ndarray&#x4E2D;&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x7C7B;&#x578B;&#x90FD;&#x662F;&#x76F8;&#x540C;&#x7684;&#xFF0C;&#x800C;Python&#x5217;&#x8868;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x7C7B;&#x578B;&#x662F;&#x4EFB;&#x610F;&#x7684;&#xFF0C;&#x6240;&#x4EE5;ndarray&#x5728;&#x5B58;&#x50A8;&#x5143;&#x7D20;&#x65F6;&#x5185;&#x5B58;&#x53EF;&#x4EE5;&#x8FDE;&#x7EED;&#xFF0C;&#x800C;python&#x539F;&#x751F;list&#x5C31;&#x53EA;&#x80FD;&#x901A;&#x8FC7;&#x5BFB;&#x5740;&#x65B9;&#x5F0F;&#x627E;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x8FD9;&#x867D;&#x7136;&#x4E5F;&#x5BFC;&#x81F4;&#x4E86;&#x5728;&#x901A;&#x7528;&#x6027;&#x80FD;&#x65B9;&#x9762;Numpy&#x7684;ndarray&#x4E0D;&#x53CA;Python&#x539F;&#x751F;list&#xFF0C;&#x4F46;&#x5728;&#x79D1;&#x5B66;&#x8BA1;&#x7B97;&#x4E2D;&#xFF0C;Numpy&#x7684;ndarray&#x5C31;&#x53EF;&#x4EE5;&#x7701;&#x6389;&#x5F88;&#x591A;&#x5FAA;&#x73AF;&#x8BED;&#x53E5;&#xFF0C;&#x4EE3;&#x7801;&#x4F7F;&#x7528;&#x65B9;&#x9762;&#x6BD4;Python&#x539F;&#x751F;list&#x7B80;&#x5355;&#x7684;&#x591A;&#x3002;</p>
<h4 id="42-ndarray&#x652F;&#x6301;&#x5E76;&#x884C;&#x5316;&#x8FD0;&#x7B97;&#xFF08;&#x5411;&#x91CF;&#x5316;&#x8FD0;&#x7B97;&#xFF09;">4.2 ndarray&#x652F;&#x6301;&#x5E76;&#x884C;&#x5316;&#x8FD0;&#x7B97;&#xFF08;&#x5411;&#x91CF;&#x5316;&#x8FD0;&#x7B97;&#xFF09;</h4>
<p>numpy&#x5185;&#x7F6E;&#x4E86;&#x5E76;&#x884C;&#x8FD0;&#x7B97;&#x529F;&#x80FD;&#xFF0C;&#x5F53;&#x7CFB;&#x7EDF;&#x6709;&#x591A;&#x4E2A;&#x6838;&#x5FC3;&#x65F6;&#xFF0C;&#x505A;&#x67D0;&#x79CD;&#x8BA1;&#x7B97;&#x65F6;&#xFF0C;numpy&#x4F1A;&#x81EA;&#x52A8;&#x505A;&#x5E76;&#x884C;&#x8BA1;&#x7B97;</p>
<h4 id="43-&#x6548;&#x7387;&#x8FDC;&#x9AD8;&#x4E8E;&#x7EAF;python&#x4EE3;&#x7801;">4.3 &#x6548;&#x7387;&#x8FDC;&#x9AD8;&#x4E8E;&#x7EAF;Python&#x4EE3;&#x7801;</h4>
<p>Numpy&#x5E95;&#x5C42;&#x4F7F;&#x7528;C&#x8BED;&#x8A00;&#x7F16;&#x5199;&#xFF0C;&#x5185;&#x90E8;&#x89E3;&#x9664;&#x4E86;GIL&#xFF08;&#x5168;&#x5C40;&#x89E3;&#x91CA;&#x5668;&#x9501;&#xFF09;&#xFF0C;&#x5176;&#x5BF9;&#x6570;&#x7EC4;&#x7684;&#x64CD;&#x4F5C;&#x901F;&#x5EA6;&#x4E0D;&#x53D7;Python&#x89E3;&#x91CA;&#x5668;&#x7684;&#x9650;&#x5236;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x5176;&#x6548;&#x7387;&#x8FDC;&#x9AD8;&#x4E8E;&#x7EAF;Python&#x4EE3;&#x7801;&#x3002;</p>
<h2 id="5-&#x5C0F;&#x7ED3;">5 &#x5C0F;&#x7ED3;</h2>
<ul>
<li>numpy&#x4ECB;&#x7ECD;&#x3010;&#x4E86;&#x89E3;&#x3011;<ul>
<li>&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x7684;Python&#x79D1;&#x5B66;&#x8BA1;&#x7B97;&#x5E93;</li>
<li>&#x8BA1;&#x7B97;&#x8D77;&#x6765;&#x8981;&#x6BD4;python&#x7B80;&#x6D01;&#x9AD8;&#x6548;</li>
<li>Numpy&#x4F7F;&#x7528;ndarray&#x5BF9;&#x8C61;&#x6765;&#x5904;&#x7406;&#x591A;&#x7EF4;&#x6570;&#x7EC4;</li>
</ul>
</li>
<li>ndarray&#x4ECB;&#x7ECD;&#x3010;&#x4E86;&#x89E3;&#x3011;<ul>
<li>NumPy&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;N&#x7EF4;&#x6570;&#x7EC4;&#x7C7B;&#x578B;ndarray&#xFF0C;&#x5B83;&#x63CF;&#x8FF0;&#x4E86;&#x76F8;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x201C;items&#x201D;&#x7684;&#x96C6;&#x5408;&#x3002;</li>
<li>&#x751F;&#x6210;numpy&#x5BF9;&#x8C61;:np.array()</li>
</ul>
</li>
<li>ndarray&#x7684;&#x4F18;&#x52BF;&#x3010;&#x638C;&#x63E1;&#x3011;<ul>
<li>&#x5185;&#x5B58;&#x5757;&#x98CE;&#x683C;<ul>
<li>list -- &#x5206;&#x79BB;&#x5F0F;&#x5B58;&#x50A8;,&#x5B58;&#x50A8;&#x5185;&#x5BB9;&#x591A;&#x6837;&#x5316;</li>
<li>ndarray -- &#x4E00;&#x4F53;&#x5F0F;&#x5B58;&#x50A8;,&#x5B58;&#x50A8;&#x7C7B;&#x578B;&#x5FC5;&#x987B;&#x4E00;&#x6837;</li>
</ul>
</li>
<li>ndarray&#x652F;&#x6301;&#x5E76;&#x884C;&#x5316;&#x8FD0;&#x7B97;&#xFF08;&#x5411;&#x91CF;&#x5316;&#x8FD0;&#x7B97;&#xFF09;</li>
<li>ndarray&#x5E95;&#x5C42;&#x662F;&#x7528;C&#x8BED;&#x8A00;&#x5199;&#x7684;,&#x6548;&#x7387;&#x66F4;&#x9AD8;,&#x91CA;&#x653E;&#x4E86;GIL</li>
</ul>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../Numpy/index.html" class="navigation navigation-prev " aria-label="Previous page: Numpy"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../Numpy/section2.html" class="navigation navigation-next " aria-label="Next page: N维数组-ndarray"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"katex":{},"expandable-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
